package com.lingyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingyi.common.utils.StringUtils;
import com.lingyi.system.domain.MaterialLib;
import com.lingyi.system.domain.vo.MaterialLibVo;
import com.lingyi.system.mapper.MaterialLibMapper;
import com.lingyi.system.service.IMaterialLibService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PackageName: com.lingyi.system.service.impl
 * @ClassName: MaterialLibServiceImpl
 * @Description:
 * @Author: czl
 * @Date: 2025/4/19 18:36
 */
@Service
@RequiredArgsConstructor
public class MaterialLibServiceImpl extends ServiceImpl<MaterialLibMapper, MaterialLib> implements IMaterialLibService {

    @Override
    public Page<MaterialLib> selectPage(MaterialLibVo search) {
        LambdaQueryWrapper<MaterialLib> queryWrapper = Wrappers.lambdaQuery(MaterialLib.class);
        queryWrapper.like(StringUtils.isNotEmpty(search.getMaterialName()), MaterialLib::getMaterialName, search.getMaterialName());
        queryWrapper.eq(StringUtils.isNotEmpty(search.getType()), MaterialLib::getType, search.getType());
        queryWrapper.eq(StringUtils.isNotEmpty(search.getMediaId()), MaterialLib::getMediaId, search.getMediaId());
        return page(search.build(), queryWrapper);
    }

    @Override
    public MaterialLib getDetailById(Long materialId) {
        return getById(materialId);
    }

    @Override
    public List<MaterialLib> allList(MaterialLibVo search) {
        LambdaQueryWrapper<MaterialLib> queryWrapper = Wrappers.lambdaQuery(MaterialLib.class);
        queryWrapper.like(StringUtils.isNotEmpty(search.getMaterialName()), MaterialLib::getMaterialName, search.getMaterialName());
        queryWrapper.eq(StringUtils.isNotEmpty(search.getType()), MaterialLib::getType, search.getType());
        queryWrapper.eq(StringUtils.isNotEmpty(search.getMediaId()), MaterialLib::getMediaId, search.getMediaId());
        return list(queryWrapper);
    }
}
